package com.lldpet.spring.cloud.demo.payment.service.listener;

import cn.ygyg.common.utils.JsonUtils;
import com.lldpet.spring.cloud.demo.order.client.channel.OrderSource;
import com.lldpet.spring.cloud.demo.order.client.event.OrderCreateSuccessEvent;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.bus.SpringCloudBusClient;
import org.springframework.cloud.bus.event.RemoteApplicationEvent;
import org.springframework.cloud.stream.annotation.EnableBinding;
import org.springframework.cloud.stream.annotation.StreamListener;
import org.springframework.context.annotation.Configuration;

/**
 * @desc：OrderCreateListener
 * @author: guanliang.xue
 * @date: 2021/5/10 15:26
 * @version:
 * @since:
 */
@Configuration
public class OrderCreateListener {
    private static final Logger logger = LoggerFactory.getLogger(OrderCreateListener.class);


    @StreamListener(SpringCloudBusClient.INPUT)
    public void onOrderCreateSuccessEvent(RemoteApplicationEvent remoteApplicationEvent){
        if(remoteApplicationEvent instanceof OrderCreateSuccessEvent){
            logger.info("payment-service 监听到 订单创建成功事件");
            logger.info("orderCreateSuccessEvent: {}", JsonUtils.toText(remoteApplicationEvent));
        }

        // todo 监听到事件后到业务逻辑处理

    }
}
